﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Sinacor.Infra.Service.Data;
using Sinacor.Service.Infra.AuthorizationService.BusinessEntity;

namespace Sinacor.Service.Infra.AuthorizationService.ResourceAccess
{
	public class User
	{
		public BusinessEntity.User RetrieveUser(int userId)
		{
            BusinessEntity.User user = new BusinessEntity.User();

            StringBuilder query = new StringBuilder();
            query.Append(@"SELECT CD_USUARIO,NM_USUARIO,CD_LOGIN 
                         FROM TGEUSUARIO 
                         WHERE CD_USUARIO = " + userId);

            OracleDataBase db = new OracleDataBase();
            DbCommand cmd = db.GetSqlStringCommand(query.ToString());

            using (IDataReader dr = db.ExecuteReader(cmd))
			{
				if (dr.Read())
				{
                    user.Id = int.Parse(dr["CD_USUARIO"].ToString());
                    user.Name = dr["NM_USUARIO"].ToString();
                    user.LoginName = dr["CD_LOGIN"].ToString();
                }
            }
            
            return user;
		}
	}
}